/*  minesweeper board object for ND++ minesweeeper game
Programmer:  Prof. Scott

This class will be used as the main object of our initial minesweeper game

The two functions callable by the client (in this case main) are the constructor, that takes #rows, # cols and # of bombs
for this specific game and play, which takes user input until either a bomb is clicked (boom!) and the game is over,
or no more non-bomb cells remain (i.e. the field is clear)

There are two private member functions used by play.  The first prints the board, leveraging polymorphism such that
the "display" virtual function is used.  If we wanted to add another class (say chicken) that wanders to the nearest 
bomb and unmarks it, it would be easy to do as this class remains unchanged.

bombSweep is a recursive search for a given cell (a, b) that is -1 by default.  If there is at least one neighbor, the
neigbor is stored in the cell and will be displayed.  If there are no neighbors, bombSweep is run on all 8 neighboring cells.
This achieves a "real time" sweep such that we only compute neighbors when we need to (efficient overall)

The cells will be constructed using new and stored in a 2D vector.  We'll also store the number of rows, columns and
nonBomb cells.  We don't care about how many bombs there are in this particular implementation but one could.

*/

#ifndef BOARD_H
#define BOARD_H

#include <QWidget>
#include <vector>   // vector class
#include "cell.h"   // include base class

using namespace std;

class Board : public QWidget {
 Q_OBJECT // compiler macro
 public:
  Board(QWidget* = 0, int = 10, int = 10, int = 10, int = 512, int = 512);  // constructor with "fall back" values

 protected:
	void paintEvent(QPaintEvent*); // repaints screen
	void mousePressEvent(QMouseEvent*); // responds to click

 private:
  void play(QMouseEvent*);    // play function  
  void printBoard();  // displays bombs
  void resetBoard(); // makes new game on board
  void bombSweep(int, int);  // recursive sweep to find neighboring bombs

  vector< vector < Cell * > > grid;  // grid; base class pointers enable polymorphic behavior
  
  int screen_width;
  int screen_height; // size of qt screen
  int board_rows;   // # of rows
  int board_cols;   // # of cols
  int nonBombCells; // # of non-bomb cells
  int bombCount; // # of bombs
  bool showbombs;
};

#endif
